package Shuffle;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Shuffle {
public static final String[]SUIT={"♥","♠","♣","♦"};
public static final String[]RANK={"A","2","3","4","5","6","7","8","9","10","J","Q","k"};


//买一副牌
private static List<Card>buyDeck(){
    List<Card>deck=new ArrayList<>(52);
    for (int i = 0; i <4 ; i++) {
        for (int j = 0; j <13 ; j++) {
            Card card=new Card();
            card.rank=RANK[j];
            card.suit=SUIT[i];
            deck.add(card);
        }
    }
    return deck;
    }

    private static void swap(List<Card>deck,int i,int j){
    Card t=deck.get(i);
    deck.set(i,deck.get(j));
    deck.set(j, t);
    }

    private static void shuffle(List<Card>deck){
        Random ra=new Random();
        for (int i = 1;i <deck.size(); i++) {
            int x= ra.nextInt(52);
            swap(deck,x,i);
        }
    }

    public static void main(String[] args) {
        List<Card>deck=buyDeck();
        System.out.println("刚买的新牌");
        System.out.println(deck);
        //洗牌
       shuffle(deck);
        System.out.println("洗牌后");
        System.out.println(deck);

        List<List<Card>>hands=new ArrayList<>();
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());
        for (int i = 0; i <6 ; i++) {
            for (int j = 0; j <3 ; j++) {
                hands.get(j).add(deck.remove(0));
            }
        }
        System.out.println("A抓的牌：");
        System.out.println(hands.get(0));
        System.out.println("B抓的牌：");
        System.out.println(hands.get(1));
        System.out.println("C抓的牌：");
        System.out.println(hands.get(2));
        System.out.println("剩余的牌：");
        System.out.println(deck);
    }


}
